package com.open.capacity.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.open.capacity.mapper.BusinessDataMapper;
import com.open.capacity.model.BusinessData;
import com.open.capacity.model.PageModel;
import com.open.capacity.service.BusinessDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.List;

@Service
public class BusinessDataServiceImpl implements BusinessDataService {
    @Autowired
    private BusinessDataMapper dataMapper;

    @Override
    public void add(BusinessData businessData) {
        dataMapper.add(businessData);
    }

    @Override
    public void delete(Long id) {
        dataMapper.delete(id);
    }

    @Override
    public void update(BusinessData businessData) {
        dataMapper.update(businessData);
    }

    @Override
    public BusinessData findById(Long id) {
        return dataMapper.findById(id);
    }

    @Override
    public PageInfo<BusinessData> findPage(PageModel pageModel) {
        PageHelper.startPage(pageModel.getPage(), pageModel.getLimit());
        List<BusinessData> all = dataMapper.findAll();
        return new PageInfo<>(all);
    }

    @Override
    public void updatePassword(String passwd,Long busiid) {
        String p = DigestUtils.md5DigestAsHex(passwd.getBytes());
        dataMapper.updatePassword(p,busiid);
    }

    @Override
    public void updateHead(BusinessData businessData) {
        dataMapper.updateHead(businessData);
    }
}
